package com.liruo.treasureattic.starter.oss.model.properties;

import com.liruo.treasureattic.starter.oss.exception.FileSeparatorException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;

/**
 * @Author:liruo
 * @Date:2022-12-05-17:16:16
 * @Desc
 */
@ConfigurationProperties("oss.tc")
@Data
public class TencentCloudOssProperties {
    private String secretId;
    private String secretKey;
    private String region;
    private String defaultBucket;

    /**
     * 可有可无，如果有，useDefaultLocalRootDir是true，每次都会使用该dir为本地root文件夹
     * 不能以 / 或者 \\ 结束
     */
    private String defaultDownloadLocalDir;
    /**
     * 默认 处理器个数 + 1
     */
    private Integer threads = Runtime.getRuntime().availableProcessors() + 1 ;

    /**
     * 分块上传阈值和分块大小默认为10MB
     */

    @PostConstruct
    private void init(){
        if(defaultBucket.endsWith("/")){
            throw new FileSeparatorException("defaultBucket can't end with /");
        }
        if(defaultDownloadLocalDir != null && (defaultDownloadLocalDir.endsWith("/") || defaultDownloadLocalDir.endsWith("\\"))){
            throw new FileSeparatorException("defaultDownloadLocalDir can't end with / or \\");
        }
    }
}
